import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Deal {
    public static void main(String[] args) throws IOException {
        String base = "/Users/anorak/Documents/JavaProject/standalone/Akby/akka/src/main/java/";
        BufferedImage image = ImageIO.read(new File(base + "one.png"));
        int width = image.getWidth();
        int height = image.getHeight();
        System.out.println("图片的尺寸为：" + width + "*" + height);
        List<String> nums = new ArrayList<>();
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                int rgb = image.getRGB(x, y);
                int alpha = (rgb >> 24) & 0xFF;
                int red =   (rgb >> 16) & 0xFF;
                int green = (rgb >>  8) & 0xFF;
                int blue =  (rgb      ) & 0xFF;
                int num = green + red + blue;
                if ( num == 765 && alpha != 0){
                    nums.add(y + "-" + x);
                }
            }
        }
        System.out.println(nums);

        // 开始比对
        BufferedImage imageAll = ImageIO.read(new File(base + "all.png"));
        int widthAll = imageAll.getWidth();
        int heightAll = imageAll.getHeight();
        System.out.println("图片的尺寸为：" + widthAll + "*" + heightAll);
        for (int i = 0; i < 295; i++){
            boolean flag = true;
            for (String num : nums) {
                String[] strings = num.split("-");
                int rgb = imageAll.getRGB(Integer.parseInt(strings[1])+i, Integer.parseInt(strings[0]));
                int alpha = (rgb >> 24) & 0xFF;
                int red =   (rgb >> 16) & 0xFF;
                int green = (rgb >>  8) & 0xFF;
                int blue =  (rgb      ) & 0xFF;
                int numAll = green + red + blue;
                if ( numAll == 765 && alpha != 0){
                    continue;
                }else {
                    flag = false;
                    break;
                }
            }
            if (flag){
                System.out.println("移动 "+ i);
                break;
            }
        }
    }


//    public static void main(String[] args) {
//        String one = "iVBORw0KGgoAAAANSUhEUgAAAC8AAACbCAYAAADyfMLPAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAR30lEQVR4nO2deZBlVX2Av3Puuctbe19mYXA2YKaGEQcMixApFUMU3BLBuESQQgOaKo0hopiqxC2JS5lIEkhK0SRiYaiCg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NPEFh1w+xwmCmmwyt62HVpasosnDNJBEAvn8WAM6MIphFpCWIwfYsGInln1ktyZutZdxLL6V+xQfI33sFkSoT/MkHyQBvFa1YDPSeuJkjoyGjD9ZZc+I+inqeye9NIbYqej/71xyd2MLc/aOcvLmX6i2HiN/z9tYyJangASn3YxnHj7YRchpSlfAToLnktOzTEwWQALzvI8Q5qJu+TAikBvTHP4/+5BcoWPBWnowHPPnvIY/fHhMNaMT0FIVagW4/Izz9VdhTPsLYo7cxtHaCuCrxDx/GHs0pA/zwAZKZSeKnx7GNfUjXj99/InMP3UIph2jhvMQ519owXa580Tkmrzgf8/Uvs9h7zavWkG7dTAloDEJhaCvxrjtwn76Mig9NCXPTIcXTz2Pg6IPYR3eip9fjz40w76+iMVIn/PxZVDZ7yPXrCfxpsu9eCSM1pNSt9fzAMMWiT3TrJZiBPiSg/HDemHhZ434xGfm1+McL4+NH1w4NDY8u+2Sk2airX8XtJctB55nMskwu90xqKQ087jSwHTcQWXjhp4Ev+H6bXyd+o2/T6si3i458u+jIt4uOfLvoyLeLjny76Mi3i458u+jIt4v/AerPnQ2ZUQJdAAAAAElFTkSuQmCC";
//        BASE64Decoder decoder = new BASE64Decoder();
//        one = one.replaceAll(" ", "+");
//        ByteArrayInputStream stream = null;
//        try {
//            byte[] buffer = decoder.decodeBuffer(one.replace("data:image/jpeg;base64", ""));
//            for(int i = 0;i<buffer.length;i++){
//                if(buffer[i] < 0){
//                    buffer[i] += 256;
//                }
//            }
//            //生成流
//            stream = new ByteArrayInputStream(buffer);
//            BufferedImage image = ImageIO.read(stream);
//            int width = image.getWidth();
//            int height = image.getHeight();
//            System.out.println("图片的尺寸为：" + width + "*" + height);
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//
//
//    }

}
